package util;

import java.util.Base64;

public class PasswordUtil {
    private static final String SALT = "LYH2025"; // 简单盐值

    public static String encrypt(String plainPassword) {
        String salted = SALT + plainPassword;
        return Base64.getEncoder().encodeToString(salted.getBytes());
    }

    public static String decrypt(String encryptedPassword) {
        byte[] decoded = Base64.getDecoder().decode(encryptedPassword);
        String result = new String(decoded);
        return result.replaceFirst(SALT, ""); // 去掉盐值
    }

    public static boolean matches(String inputPassword, String encryptedPassword) {
        return encrypt(inputPassword).equals(encryptedPassword);
    }
}